<template>
  <div class="did-h">
    <div class="black black">
      <div>创建战术</div>
      <el-row :gutter="20" class="mt3">
        <el-col :span="10" :offset="6">
          <el-form label-position="right" label-width="110px" :model="form">
            <el-form-item label="选择战术链">
              <el-cascader :options="cascaderOptions" :props="cascaderProps" clearable @change="handleCascaderChange"></el-cascader>
            </el-form-item>
            <el-form-item label="战术名称">
              <el-input v-model="form.name" placeholder="请输入战术名称"></el-input>
            </el-form-item>
            <el-form-item label="选择战术参与者">
              <span class="demonstration"></span>
              <el-cascader :options="userListOptions" :props="userListProps" clearable @change="handleCascaderChange1"></el-cascader>
            </el-form-item>
            <el-form-item label="输入战术内容">
              <el-input type="textarea" :autosize="{ minRows: 2, maxRows: 6 }" placeholder="请输入内容" v-model="form.content"> </el-input>
            </el-form-item>
          </el-form>
        </el-col>
      </el-row>
      <div class="did-button">
        <el-button size="medium" type="primary" @click="creatTactics()">发布战术</el-button>
      </div>
    </div>
  </div>
</template>
  <script>
import NoData from '../../components/noData.vue';
export default {
  created() {
    this.getChainList();
  },
  components: {
    NoData,
  },
  data() {
    return {
      activeName: 'first',
      form: {
        tacticalChainDid: '',
        executors: '',
        content: '',
        name: '',
      },
      data: '',
      //级联选择器1
      userListOptions: [],
      userListProps: {
        multiple: true,
        value: 'userDid',
        label: 'userName',
      },
      //级联选择器2
      cascaderOptions: [],
      cascaderProps: {
        multiple: false,
        value: 'tacticalChainDid',
        label: 'tacticalName',
      },
    };
  },
  mounted() {},
  methods: {
    //获取当前战术链用户列表
    async getUserListBychainId() {
      const chainDid = this.form.tacticalChainDid;
      let res = await this.$http.post(this.$api.tacticalChain.getUserListBychainId, chainDid);
      console.info(res);
      this.userListOptions = res.data;
    },
    //获取当前战术链列表
    async getChainList() {
      let res = await this.$http.post(this.$api.tacticalChain.queryTacticalChainList);
      console.info(res);
      this.cascaderOptions = res.page.list;
    },
    async creatTactics() {
      console.info(this.form);
      let formData = new FormData();
      formData.append('tacticalChainDid', this.form.tacticalChainDid);
      formData.append('executors', this.form.executors);
      formData.append('content', this.form.content);
      formData.append('name', this.form.name);
      console.info(formData);
      let res = await this.$http.post(this.$api.tacticalChain.createTactical, formData);
      if (res.code == 0) {
        this.resetForm();
        this.$notify({
          title: '成功',
          message: '创建战术链成功',
          type: 'success'
        });
      }
    },
    //获取级联选择器2的数值 选择的战术链
    handleCascaderChange(selectedValues) {
      this.form.tacticalChainDid = selectedValues;
      this.getUserListBychainId();
      console.log('Selected values:', selectedValues);
    },
    //获取级联选择器1的数值 选择的参与用户
    handleCascaderChange1(selectedValues) {
      this.form.executors = selectedValues;
      console.log('Selected values:', selectedValues);
    },
    resetForm() {
      // 重置表单数据对象为空
      this.form = {
        tacticalChainDid: '',
        executors: '',
        content: '',
        name: '',
      };
      this.cascaderOptions = '',
      this.userListOptions = ''
      this.getChainList();
    },
  },
};
</script>
  <style lang="less" scoped>
.did-content {
  margin-top: 10%;
  h1 {
    color: #666666;
    width: 320px;
    margin: 0 auto;
  }
}
.did-button {
  width: 100px;
  margin: 0 auto;
  margin-top: 20px;
}
.m-a0 {
  margin: 0 auto;
}
.black-h {
  height: 100%;
}
.black-height {
  height: calc(50% - 90px);
}
.nodata {
  margin-top: 10%;
}
.did-width {
  width: 500px;
  margin: 0 auto;
}
.text-c {
  text-align: center;
  font-size: 20px;
  font-weight: 600;
}
</style>
  